﻿<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Option Explicit %>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" />
<META NAME="copyright" CONTENT="Copyright 2009-2010 - Martechina Co.Ltd" />
<META NAME="Author" CONTENT="劢格机械(中国)  Www.Martechina.Com" />
<META NAME="Keywords" CONTENT="" />
<META NAME="Description" CONTENT="" />
<TITLE>编辑产品</TITLE>
<link href="css.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../inc/Admin.js"></script>
</HEAD>
<!--#include file="../inc/Const.asp" -->
<!--#include file="../inc/ConnSiteData.asp" -->
<!--#include file="CheckAdmin.asp"-->
<%
'cookie 验证
'if Instr(request.cookies("Martech_com")("AdminPurview"),"|21,")=0 then 
'  response.write ("<font color='red')>你不具有该管理模块的操作权限，请返回！</font>")
'  response.end
'end if

'session 验证
if Instr(session("AdminPurview"),"|21,")=0 then 
  response.write ("<font color='red')>你不具有该管理模块的操作权限，请返回！</font>")
  response.end
end if
'========判断是否具有管理权限
%>
<BODY>
<% 
dim Result
Result=request.QueryString("Result")
dim ID,Name,ViewFlag,SortName,SortID,SortPath,Key,miaoshu
dim ProductNo,ProductModel,N_Price,P_Price,Stock,Unit,Maker,CommendFlag,NewFlag,GroupID,GroupIdName,Exclusive
dim BigPic,SmallPic,Content
ID=request.QueryString("ID")
call ProductEdit() 
%>

<table border="0" cellspacing="1" cellpadding="0" height="0" align="center" width="100%" >
  <tr>
  <td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff">

  <tr class=classtop>
    <td height="24" align="center" nowrap ><a href="ProductEdit.asp?Result=Add" onClick='changeAdminFlag("添加产品信息")'>添加产品信息</a><font color="#0000FF">&nbsp;|&nbsp;</font><a href="ProductList.asp" onClick='changeAdminFlag("产品列表")'>查看所有产品信息</a></td>
  </tr>
</table>
<br>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff">
<script language="javascript">
// 参数说明
// s_Type : 文件类型，可用值为"image","flash","media","file"
// s_Link : 文件上传后，用于接收上传文件路径文件名的表单名
// s_Thumbnail : 文件上传后，用于接收上传图片时所产生的缩略图文件的路径文件名的表单名，当未生成缩略图时，返回空值，原图用s_Link参数接收，此参数专用于缩略图
function showUploadDialog(s_Type, s_Link, s_Thumbnail){
	//以下style=coolblue,值可以依据实际需要修改为您的样式名,通过此样式的后台设置来达到控制允许上传文件类型及文件大小
	var arr = showModalDialog("../martech_editor/dialog/i_upload.htm?style=light&type="+s_Type+"&link="+s_Link+"&thumbnail="+s_Thumbnail, window, "dialogWidth:0px;dialogHeight:0px;help:no;scroll:no;status:no");
}
</script>
  <form name="editForm" method="post" action="ProductEdit.asp?Action=SaveEdit&Result=<%=Result%>&ID=<%=ID%>">

<tr>
 <td height="27" colspan="4" align="center" class="classtop"><strong>增加修改产品</strong></td>
</tr>
      <tr class=classtd>
        <td   height="20" align="right">产品名称：</td>
        <td  ><input name="Name" type="text" class="textfield" id="Name" style="WIDTH: 240;" value="<%=Name%>" maxlength="100">&nbsp;发布：
          <input name="ViewFlag" type="checkbox" style='HEIGHT: 13px;WIDTH: 13px;' value="1" checked <%if ViewFlag then response.write ("checked")%>>          &nbsp;*&nbsp;不少于1个字符</td>
      </tr>
      <tr class=classtd>
        <td height="20" align="right"  >关键字：</td>
        <td  ><input name="Key" type="text" class="textfield" id="Key" style="WIDTH: 240;" value="<%=Key%>" maxlength="100">
          &nbsp;发布：
&nbsp;&nbsp;6个词以内用<b>，</b>号隔开</td>
      </tr>
        <tr class=classtd>
        <td height="20" align="right"  >描　　述：</td>
       <td  ><textarea name="miaoshu" rows="3" class="textfield" id="miaoshu" style="WIDTH: 440;"><%=miaoshu%></textarea>&nbsp;发布：&nbsp;&nbsp;250个字符以内</td> 
      </tr>
      <tr class=classtd>
        <td   height="20" align="right">所属类别：</td>
        <td  ><input name="SortName" type="text" class="textfield" id="SortName" value="<%=SortName%>" style="WIDTH: 240;" readonly>&nbsp;<a href="javaScript:OpenScript('SelectSort.asp?Result=Products',500,500,'')"><img src="../images/Select.gif" width="30" height="16" border="0" align="absmiddle"></a></td>
      </tr>
      <tr class=classtd>
        <td   height="20" align="right">类别数字：</td>
        <td  ><input name="SortID" type="text" class="textfield" id="SortID" style="WIDTH: 40;" value="<%=SortID%>" readonly><input name="SortPath" type="text" class="textfield" id="SortPath" style="WIDTH: 200;" value="<%=SortPath%>" readonly>&nbsp;*</td>
      </tr>
      <tr class=classtd>
        <td   height="20" align="right">编　　号：</td>
        <td  ><input name="ProductNo" type="text" class="textfield" id="ProductNo" style="WIDTH: 240;" value="<%=ProductNo%>" maxlength="100">&nbsp;*&nbsp;如果不明确请勿修改</td>
      </tr>
      <tr class=classtd>
        <td   height="20" align="right">型　　号：</td>
        <td  ><input name="ProductModel" type="text" class="textfield" id="ProductModel" style="WIDTH: 240;" value="<%=ProductModel%>" maxlength="100">&nbsp;*&nbsp;</td>
      </tr>
      <tr class=classtd>
        <td   height="20" align="right">标 准 价：</td>
        <td  ><input name="N_Price" type="text" class="textfield" id="N_Price" style="WIDTH: 240;" value="<%=N_Price%>" maxlength="100">&nbsp;*&nbsp;</td>
      </tr>	  
      <tr class=classtd>
        <td   height="20" align="right">优 惠 价：</td>
        <td  ><input name="P_Price" type="text" class="textfield" id="P_Price" style="WIDTH: 240;" value="<%=P_Price%>" maxlength="100">&nbsp;*&nbsp;</td>
      </tr>
      <tr class=classtd>
        <td   height="20" align="right">库存数量：</td>
        <td  ><input name="Stock" type="text" class="textfield" id="Stock" style="WIDTH: 240;" value="<%=Stock%>" maxlength="100">&nbsp;*</td>
      </tr>	  
      <tr class=classtd>
        <td   height="20" align="right">计价单位：</td>
        <td  ><input name="Unit" type="text" class="textfield" id="Unit" style="WIDTH: 240;" value="<%=Unit%>" maxlength="100">&nbsp;*&nbsp;</td>
      </tr>	 
	    <tr class=classtd>
        <td   height="20" align="right">出品公司：</td>
        <td  ><input name="Maker" type="text" class="textfield" id="Maker" style="WIDTH: 240;" value="<%=Maker%>" maxlength="100"></td>
      </tr>
      <tr class=classtd>
        <td   height="20" align="right">状　　态：</td>
        <td  ><input name="CommendFlag" type="checkbox" style="HEIGHT: 13px;WIDTH: 13px;" value="1" <%if CommendFlag then response.write ("checked")%>>
        &nbsp;推荐&nbsp;
<input name="NewFlag" type="checkbox" value="1" style="HEIGHT: 13px;WIDTH: 13px;" <%if NewFlag then response.write ("checked")%>>&nbsp;最新</td>
      </tr>
    <tr class=classtd>
        <td   height="20" align="right">缩 略 图：</td>
        <td  ><input name="SmallPic" type="text" class="textfield" style="WIDTH: 240; height:25;" value="<%=SmallPic%>" maxlength="100">&nbsp;<input type=button class="button" style="WIDTH: 80;" value="上传缩图" onClick="showUploadDialog('image', 'editForm.SmallPic', '')"></td>
      </tr>
      <tr class=classtd>
        <td   height="20" align="right">产品主图：</td>
        <td  ><input name="BigPic" type="text" class="textfield" style="WIDTH: 240; height:25;" value="<%=BigPic%>" maxlength="100">&nbsp;<input type=button class="button" style="WIDTH: 80;" value="上传主图" onClick="showUploadDialog('image', 'editForm.BigPic', '')"></td>
      </tr>
     
      <tr class=classtd>
        <td   height="20" align="right" valign="top">详细介绍：<br>
		      <td  > <textarea name="content" style="display:none"><%=Server.HtmlEncode(Content)%></textarea>
        <!--  <IFRAME ID="eWebEditor1" src="/martech_editor/ewebeditor.asp?id=content&style=s_light" frameborder="0" scrolling="no" width="650" height="350"></IFRAME>--><IFRAME ID="eWebEditor1" SRC="../martech_editor/ewebeditor.htm?id=content&style=light" FRAMEBORDER="0" SCROLLING="no" WIDTH="650" HEIGHT="350"></IFRAME></td>
      </tr>

      <tr class=classtd>
        <td   height="30" align="right">&nbsp;</td>
        <td   valign="bottom"><input name="submitSaveEdit" type="submit" class="button"  id="submitSaveEdit" value="保存" style="WIDTH: 80;" ></td>
      </tr>
  </form>
</table>
</td>
</tr>
</table>
</BODY>
</HTML>
<%
sub ProductEdit()
  dim Action,rsRepeat,rs,sql
  Action=request.QueryString("Action")
  if Action="SaveEdit" then '保存编辑产品信息
    set rs = server.createobject("adodb.recordset")
    if len(trim(request.Form("Name")))<1 then
      response.write ("<script language=javascript> alert('产品名称为必填项目！');history.back(-1);</script>")
      response.end
    end if
    if Result="Add" then '创建产品信息
	  sql="select * from Martech_Product"
      rs.open sql,conn,1,3
      rs.addnew
      rs("Name")=trim(Request.Form("Name"))
	  if trim(Request.Form("Key"))=""then 
	  rs("Key")=left(trim(Request.Form("Name")),6)
	  else
	  rs("Key")=trim(Request.Form("Key"))
	  end if
	  if trim(Request.Form("Miaoshu"))="" then
	  rs("Miaoshu")=left(trim(Request.Form("Content")),255)
	  else
	  rs("Miaoshu")=trim(Request.Form("Miaoshu"))
	  end if
	    if Request.Form("ViewFlag")=1 then
        rs("ViewFlag")=Request.Form("ViewFlag")
	    else
        rs("ViewFlag")=0
	    end if
	    if Request.Form("SortID")="" and Request.Form("SortPath")="" then
        response.write ("<script language=javascript> alert('请选择所属分类！');history.back(-1);</script>")
        response.end
	    else
	      rs("SortID")=Request.Form("SortID")
		    rs("SortPath")=Request.Form("SortPath")
	    end if
      set rsRepeat = conn.execute("select ProductNo from Martech_Product where ProductNo='" & trim(Request.Form("ProductNo")) & "'")
      if not (rsRepeat.bof and rsRepeat.eof) then '判断此产品编号是否存在
        response.write "<script language=javascript> alert('" & trim(Request.Form("ProductNo")) & "此产品编号已经存在，请换一个编号再试试！');history.back(-1);</script>"
        response.end
      else
	      rs("ProductNo")=trim(Request.Form("ProductNo"))
	    end if
	    rs("ProductModel")=trim(Request.Form("ProductModel"))
	    if (not IsNumeric(trim(request.Form("N_Price")))) or (not IsNumeric(trim(request.Form("P_Price"))))then
        response.write ("<script language=javascript> alert('标准价和优惠价数据必填，且为正数！');history.back(-1);</script>")
        response.end
      elseif trim(request.Form("N_Price"))<0 or trim(request.Form("P_Price"))<0then
        response.write ("<script language=javascript> alert('标准价和优惠价数据必填，且为正数！');history.back(-1);</script>")
        response.end
      else
        rs("N_Price")=Round(trim(Request.Form("N_Price")),2)
	      rs("P_Price")=Round(trim(Request.Form("P_Price")),2)
	    end if
			if (not IsNumeric(trim(request.Form("Stock"))))  then
        response.write ("<script language=javascript> alert('库存数量必填且为数值！');history.back(-1);</script>")
        response.end
			else
			  rs("Stock")=Round(trim(Request.Form("Stock")),2)
			end if  	
			if len(trim(Request.Form("Unit")))=0 then
        response.write ("<script language=javascript> alert('计价单位必填！');history.back(-1);</script>")
        response.end
			else
			  rs("Unit")=trim(Request.Form("Unit"))
			end if  
	    rs("Maker")=trim(Request.Form("Maker"))
	    if Request.Form("CommendFlag")=1 then
        rs("CommendFlag")=Request.Form("CommendFlag")
	    else
        rs("CommendFlag")=0
	    end if
	    if Request.Form("NewFlag")=1 then
        rs("NewFlag")=Request.Form("NewFlag")
	    else
        rs("NewFlag")=0
	    end if
  
	    rs("BigPic")=trim(Request.Form("BigPic"))	  
	    rs("SmallPic")=trim(Request.Form("SmallPic"))
	    rs("Content")=rtrim(Request.Form("Content"))
	    rs("AddTime")=now()
	    rs("UpdateTime")=now()
	  end if  
	  if Result="Modify" then '修改产品信息
      sql="select * from Martech_Product where ID="&ID
      rs.open sql,conn,1,3
      rs("Name")=trim(Request.Form("Name"))
	  rs("Key")=trim(Request.Form("Key"))
	  rs("Miaoshu")=trim(Request.Form("Miaoshu"))
	    if Request.Form("ViewFlag")=1 then
        rs("ViewFlag")=Request.Form("ViewFlag")
	    else
        rs("ViewFlag")=0
	    end if
	    if Request.Form("SortID")<>"" and Request.Form("SortPath")<>"" then
	      rs("SortID")=Request.Form("SortID")
		    rs("SortPath")=Request.Form("SortPath")
	    else
        response.write ("<script language=javascript> alert('请选择所属分类！');history.back(-1);</script>")
        response.end
	    end if
	    rs("ProductNo")=trim(Request.Form("ProductNo"))
	    rs("ProductModel")=trim(Request.Form("ProductModel"))
	    if (not IsNumeric(trim(request.Form("N_Price")))) or (not IsNumeric(trim(request.Form("P_Price"))))then
        response.write ("<script language=javascript> alert('标准价和优惠价数据必填，且为正数！');history.back(-1);</script>")
        response.end
      elseif trim(request.Form("N_Price"))<0 or trim(request.Form("P_Price"))<0then
        response.write ("<script language=javascript> alert('标准价和优惠价数据必填，且为正数！');history.back(-1);</script>")
        response.end
      else
        rs("N_Price")=Round(trim(Request.Form("N_Price")),2)
	      rs("P_Price")=Round(trim(Request.Form("P_Price")),2)
	    end if
			if (not IsNumeric(trim(request.Form("Stock"))))  then
        response.write ("<script language=javascript> alert('库存数量必填且为数值！');history.back(-1);</script>")
        response.end
			else
			  rs("Stock")=Round(trim(Request.Form("Stock")),2)
			end if  	
			if len(trim(Request.Form("Unit")))=0 then
        response.write ("<script language=javascript> alert('计价单位必填！');history.back(-1);</script>")
        response.end
			else
			  rs("Unit")=trim(Request.Form("Unit"))
			end if  
	    rs("Maker")=trim(Request.Form("Maker"))
	    if Request.Form("CommendFlag")=1 then
        rs("CommendFlag")=Request.Form("CommendFlag")
	    else
        rs("CommendFlag")=0
	    end if
	    if Request.Form("NewFlag")=1 then
        rs("NewFlag")=Request.Form("NewFlag")
	    else
        rs("NewFlag")=0
	    end if
    
	    rs("BigPic")=trim(Request.Form("BigPic"))	  
	    rs("SmallPic")=trim(Request.Form("SmallPic"))
	    rs("Content")=rtrim(Request.Form("Content"))
	    rs("UpdateTime")=now()
	  end if
	  rs.update
  	rs.close
    set rs=nothing 
    response.write "<script language=javascript> alert('成功编辑产品信息！');changeAdminFlag('产品列表');location.replace('ProductList.asp');</script>"
  else '提取产品信息
  	if Result="Modify" then
      set rs = server.createobject("adodb.recordset")
      sql="select * from Martech_Product where ID="& ID
      rs.open sql,conn,1,1
      if rs.bof and rs.eof then
      response.write ("数据库读取记录出错！")
      response.end
      end if
	    Name=rs("Name")
		Key=rs("Key")
	    Miaoshu=rs("Miaoshu")
	    ViewFlag=rs("ViewFlag")
	    SortName=SortText(rs("SortID"))
	    SortID=rs("SortID")
	    SortPath=rs("SortPath")
	    ProductNo=rs("ProductNo")
        ProductModel=rs("ProductModel")
	    N_Price=rs("N_Price")
	    P_Price=rs("P_Price")
		Stock=rs("Stock")
		Unit=rs("Unit")
	    Maker=rs("Maker")
	    CommendFlag=rs("CommendFlag")
	    NewFlag=rs("NewFlag")
	  
	    BigPic=rs("BigPic")
	    SmallPic=rs("SmallPic")
        Content=rs("Content")
	    rs.close
        set rs=nothing 
	  else
	    randomize timer
	    ProductNo=Hour(now)&Minute(now)&Second(now)&"-"&int(900*rnd)+100
		Stock=10000
    end if
  end if
end sub
%>

<%
'生成所属类别--------------------------
Function SortText(ID)
  Dim rs,sql
  Set rs=server.CreateObject("adodb.recordset")
  sql="Select * From Martech_ProductSort where ID="&ID
  rs.open sql,conn,1,1
  SortText=rs("SortName")
  rs.close
  set rs=nothing
End Function
%>